import { Observable } from 'rxjs/internal/Observable';
import { RouterStateSnapshot, ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Injectable } from '@angular/core';
import { HomeService } from 'src/app/services/home.service';
import { SingerService } from 'src/app/services/singer.service';
import { Banner, HotTag, PersonSheet, Singer } from 'src/app/services/data-types/common.type';
import { forkJoin } from 'rxjs';
import { first } from 'rxjs/internal/operators/first';


type HomeDataType = [Banner[], HotTag[], PersonSheet[], Singer[]];

@Injectable()
export class HomeResolverService implements Resolve<HomeDataType> {
  constructor(private homeServe: HomeService,
    private singerServe: SingerService,) {}
  resolve(): Observable<HomeDataType> {
    //并行处理
    return forkJoin([
      this.homeServe.getBanners(),
      this.homeServe.getHotTags(),
      this.homeServe.getSongSheetList(),
      this.singerServe.getSinger()
    ]).pipe(first())  ;
  }
}
